import {Color, Scene, WebGLRenderer} from "three";
import {MapCamera} from "./MapCamera";
import {CRS} from "../crs/CRS";
import {MapScene} from "./MapScene";
import {FreeMap} from "../";

/**
 * 地图渲染器
 */
export class MapRenderer {
    public scene: MapScene;

    public camera: MapCamera;

    public renderer: WebGLRenderer;

    public map: FreeMap;

    constructor(container: HTMLElement, crs: CRS, map: FreeMap) {
        this.map = map;
        this.renderer = new WebGLRenderer({
            //抗锯齿
            antialias: true
        });
        this.renderer.setClearColor(map.config.backGroundColor as any);
        this.renderer.setPixelRatio(window.devicePixelRatio);
        this.camera = new MapCamera(container, crs, map);
        this.renderer.setSize(this.camera.width, this.camera.height);
        this.scene = new MapScene(this, map);

        container.appendChild(this.renderer.domElement);
    }

    public render() {
        this.renderer.render(this.scene, this.camera);
    }
}
